import Qt 4.7

Rectangle {
    id: container

    width: 514; height: 184
    color: "transparent"

    signal callCashFlowListView
    signal callUpdateMoneyRegisters
    signal callMessageBox(string mesgBox, string nextView)

    function updateCategories(m_model) {
        categoriesDropDown.model = m_model;
    }

    function fillForm() {
        var sp = daoManager.spSearch
        sinceInput.text = sp.dateSince
        untilInput.text = sp.dateUntil
        if (sp.category && categoriesDropDown.model.length > 0) {
            for (var i = 0; i < categoriesDropDown.model.length; i++)
                if (categoriesDropDown.model[i].id == sp.category.id)
                    categoriesDropDown.idSelected = i;
        }
    }

    MouseArea {
        // The unique purpose of bring back the dropdown
        anchors.fill: parent
        onClicked: {
            if (categoriesDropDown.state == 'extended')
                categoriesDropDown.state = 'normal';
        }
    }
    Text {
        id: byCategoriesLabel

        x: 38; y: 12
        text: "Por Categorias"; color: "black"
        font { pointSize: 7; weight: Font.DemiBold; family: "Series 60 Sans" }
    }
    Text {
        id: sinceLabel

        x: 38; y: 58
        text: "Desde"; color: "black"
        font { pointSize: 7; weight: Font.DemiBold; family: "Series 60 Sans" }
    }
    DateInput {
        id: sinceInput

        x: 119; y: 43; /*width: 95; height: 41*/
    }
    Text {
        id: untilLabel

        x: 250; y: 58
        text: "Ate"; color: "black"
        font { pointSize: 7; weight: Font.DemiBold; family: "Series 60 Sans" }
    }
    DateInput {
        id: untilInput

        x: 308; y: 43; /*width: 95; height: 41*/
    }
    Text {
        id: descriptionLabel

        x: 38; y: 103
        text: "Descricao"; color: "black"
        font { pointSize: 7; weight: Font.DemiBold; family: "Series 60 Sans" }
    }
    LineEdit {
        id: descriptionLineEdit

        x: 215; y: 90; width: 257; height: 39
    }
    Text {
        id: lessThanLabel

        x: 38; y: 153
        text: "Valor menor que"; color: "black"
        font { pointSize: 7; weight: Font.DemiBold; family: "Series 60 Sans" }
    }
    LineEdit {
        id: lessThanLineEdit

        x: 215; y: 138; width: 100; height: 39
    }
    Text {
        id: greaterThanLabel

        x: 38; y: 203
        text: "Valor maior que"; color: "black"
        font { pointSize: 7; weight: Font.DemiBold; family: "Series 60 Sans" }
    }
    LineEdit {
        id: greaterThanLineEdit

        x: 215; y: 188; width: 100; height: 39
    }
    Button {
        id: okButton

        x: 349; y: 180; width: 101; height: 53
        text: "OK"
        onClicked: {
            var sp = daoManager.spSearch
            if (categoriesDropDown.textSelected != "Todas" && categoriesDropDown.model.length > 0) {
                sp.category = categoriesDropDown.model[categoriesDropDown.idSelected];
            }
            if (sinceInput.text != "__ /__ /__")
                sp.dateSince = sinceInput.text
            if (untilInput.text != "__ /__ /__")
                sp.dateUntil = untilInput.text
            if (descriptionLineEdit.text != '')
                sp.description = descriptionLineEdit.text
            if (lessThanLineEdit.text != '')
                sp.lessValue = lessThanLineEdit.text
            if (greaterThanLineEdit.text != "")
                sp.greaterValue = greaterThanLineEdit.text
            daoManager.spSearch = sp;
            container.callMessageBox("Iniciada Busca Especifica...", 'Nope');
            container.callUpdateMoneyRegisters()
            container.callCashFlowListView();
        }
    }
    AdvancedDropDown {
        id: categoriesDropDown

        allowCreate: false
        x: 156; y:-5
    }
}
